package com.greatchn.authorization_server.web.controller;

import com.greatchn.authorization_server.util.ApiAssert;
import com.greatchn.authorization_server.util.Result;
import com.greatchn.authorization_server.web.srv.LoginSrv;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @LoginController: login
 * @author: ZBoHang
 * @time: 2023/2/28 16:08
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private LoginSrv loginSrv;

    /**
     * login
     */
    @PostMapping("/login")
    public Result login(String userName, String password) {

        ApiAssert.noneBlank(userName, "用户名不能为空!");
        ApiAssert.noneBlank(password, "密码不能为空!");

        String token = this.loginSrv.login(userName, password);

        return Result.success(token);
    }

    /**
     * check
     */
    @PostMapping("/check")
    public Result check(String userName) {

        return Result.success(userName);
    }
}
